<?php
/**
 * Created by PhpStorm.
 * User: Office
 * Date: 2017/12/22
 * Time: 14:14
 */
header("Content-type: text/html; charset=utf-8");
session_start();
$ok = false;
if (empty($_SESSION['user']) || $_SESSION['user'] !== 'admin') {
    echo '请<a href="../index.php" style="color: red">登录</a>后执行操作';
    exit;
}
//如果没有变量$_GET['entry']
if (!isset($_GET['entry'])) {
    //如果没有变量$_POST['entry']
    if (!isset($_POST['id'])) {
        $msg = '请求参数错误；<a href="../index.php">返回首页 </a>';
    } else {
        $filename = $_POST['id'];
//        如果删除了文件
        if (unlink($filename)) {
            $msg = '该日志删除成功；<a href="blog_in.php">返回日志列表</a>';
        } else {
            $msg = '该日志删除失败；<a href="../index.php">返回首页</a>';
        }
    }
    $ok = true;
} else {
    $form_data = '';
    $filename = $_GET['entry'];
//    有这个文件
    if (file_exists($filename)) {
        $form_data = '<input type="hidden" name="id" value="' . $_GET['entry'] . '">';
    } else {
        $ok = true;
        $msg = '所要删除的日志不存在;<a href="../index.php">返回首页</a>';
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>删除日志</title>
    <link rel="stylesheet" href="../css/blog.css">

</head>
<body>

<div class="box">
    <header>
        <h2>我的BLOG</h2>
    </header>
    <div class="content clearBox">

        <div class="left">
            <h5 class="title">删除日志</h5>
            <?php if (!$ok) { ?>
                <form action="delete.php" method="post" name="del">
                    <p style="color: red;font-weight: bold;margin-bottom: 30px">删除的日志无法恢复，您确定要删除？</p>
                    <button type="submit" name="btn">狠心删除</button>
                    <?php echo $form_data; ?>
                </form>
            <?php } ?>
            <?php if ($ok) {
                echo "<div style='padding-top: 10px'>" . $msg . "</div>";
            } ?>
        </div>
        <div class="right">
            <div>
                <h5 class="title">关于我</h5>
                <p class="right-ctn">php初学者</p>
            </div>
        </div>
    </div>
    <div class="footer">CopyRight&nbsp;2017</div>

</body>
</html>
